const cinemasModel = require('../models/cinemasModel');

module.exports = {
    //查询影院信息
    async queryAllCinemas({ currentPage, pageSize }) {
        return await cinemasModel.find()
            .skip((currentPage - 1) * pageSize)
            .limit(pageSize)
            .sort({ "_id": -1 }).exec();
    },
    //获得数据的总条数
    async getTolNums() {
        return cinemasModel.countDocuments().exec();
    },

    //根据 id 查询影院信息
    async queryCinemas(id) {
        return await cinemasModel.findOne({ _id: id }).exec();
    },
    //根据地区查询影院信息
    async typequery(address) {
        return await cinemasModel.find({ address }).exec();
    },
    //添加影院信息
    async addCinema(name, address, phone, status, photo) {

        return await cinemasModel.create({ name, address, phone, status, photo });
    },
    //删除影院信息
    async deleteCinema(id) {
        return await cinemasModel.deleteOne({ _id: id });
    },
    //修改影院信息（带图片）
    async editCinema(_id, name, address, phone, status, photo) {
        return await cinemasModel.updateOne({ _id }, { name, address, phone, status, photo });
    },
    //修改影院信息
    async edit(_id, name, address, phone, status) {
        return await cinemasModel.updateOne({ _id }, { name, address, phone, status });
    }
}